﻿// Copyright © 2010 Silvestru Iapascurta.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see license.txt for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using FeedDotNet.Common;
using System.Windows.Forms;

namespace Karoro
{
    public static class HelperFunctions
    {

        /// <summary>
        /// Gets the focused control.
        /// </summary>
        /// <param name="controls"></param>
        /// <returns>Control</returns>
        /// <author>Scott_Morrison (MSDN)</author>
        public static Control getFocused(Control.ControlCollection controls)
        {
            foreach (Control c in controls)
            {
                if (c.Focused)
                {
                    // Return the focused control
                    return c;
                }
                else if (c.ContainsFocus)
                {
                    // If the focus is contained inside a control's children
                    // return the child
                    return getFocused(c.Controls);
                }
            }

            // No control on the form has focus
            return null;
        }
    }
}
